# -*- coding: utf-8 -*-
# @File:     generate_utils.py
# @Author:
# @DateTime: 2025/06/06/11:17
from typing import Optional

from app.models.generate import GenerateRecord
from app.utils.curd_base import ModelCRUD
from pydantic import BaseModel, Field


class CRUDGenerateTask(ModelCRUD):

    model = GenerateRecord


class CreateGenerateRecord(BaseModel):
    g_task_id: Optional[int] = Field(description='任务id')
    task_uuid: Optional[str] = Field(description='任务uuid')
    user_id: int = Field(description='用户')
    menu_id: Optional[int] = Field(description='菜单id')
    params: Optional[str] = Field(description='参数')
    send_queue: Optional[str] = Field(description='发送队列')
    order_queue: Optional[str] = Field(description='排序队列')


def crud_generate_record(task, db):

    data = {
        'g_task_id': task.id,
        'task_uuid': task.task_uuid,
        'user_id': task.user_id,
        'menu_id': task.menu_id,
        'params': task.params,
        'send_queue': task.send_queue,
        'order_queue': task.order_queue,
    }
    crud = CRUDGenerateTask()

    return crud.create(db, data=CreateGenerateRecord.validate(data))



